<?php
/**
 * tuangou.php
 * Niushop商城系统 - 团队十年电商经验汇集巨献!
 * =========================================================
 * Copy right 2015-2025 山西牛酷信息科技有限公司, 保留所有权利。
 * ----------------------------------------------
 * 官方网址: http://www.niushop.com.cn
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用。
 * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
 * =========================================================
 * @author : niuteam
 * @date : 2015.1.17
 * @version : v1.0.0.0
 */

namespace app\api\controller;

use app\Validate\DiscountListValidate;
use data\service\Pintuan;
use data\service\Order\OrderStatus;
use data\service\Express;
use think\Controller;
use data\model\NsGoodsModel;
use data\model\AlbumPictureModel;
use think\Request;
use data\model\NsPromotionTuangouModel;
use data\service\TuangouApply;
use think\cache\driver\Redis;
use data\service\Goods;

/**
 * 团购
 */
class Tuangou extends BaseController
{


    /**
     * 团购列表
     */
    public function tuangouList(DiscountListValidate $discountListValidate)
    {
        $pintuan = new Pintuan();
        $page = $discountListValidate->request->post("page", 1);
        $type = $discountListValidate->request->post("type");
        $start_time = $discountListValidate->request->post("start_time");
        $end_time = $discountListValidate->request->post("end_time");
        $number = $discountListValidate->request->post("number", 10);
        $shop_id = $this->shop_id;
        $field = ['tuangou_id', 'goods_id', 'tuangou_money', 'tuangou_num', 'tuangou_time', 'tuangou_type', 'tuangou_content_json', 'remark', 'shop_id', 'time_open'];
        $data = $pintuan->getPintuanList($type, $page, $start_time, $end_time, $number, $shop_id, $field);
        return return_json_data($data);
    }

    /**
     * 活动报名
     */
    public function activityRregistration(DiscountListValidate $discountListValidate)
    {
        $tuangou_id = $discountListValidate->request->post("tuangou_id");
        $goods_id = $discountListValidate->request->post("goods_id");

        $tuangou = new TuangouApply();
        $data_tuangou = $tuangou->activityRregistration($tuangou_id, $this->user_id, $this->shop_id, $goods_id);
        if ($data_tuangou !== true) {
            return return_json_data($data_tuangou, 500);
        }
        return return_json_data('报名成功', 200);
    }

    /**
     * 参加拼团
     * @param DiscountListValidate $discountListValidate
     */
    public function partnershipSpell()
    {
        $Pintuan = new Pintuan();
        $PintuanList = $Pintuan->getPintuanGoodsList(1, 1);
        return return_json_data($PintuanList, 200);
    }

    /**
     * 参加拼团人数查询
     * @param DiscountListValidate $discountListValidate
     */
    public function participantsNumber(DiscountListValidate $discountListValidate)
    {
        $tuangou_id = $discountListValidate->request->post('tuangou_id');
        $Pintuan = new TuangouApply();
        $data = $Pintuan->participantsNumber($tuangou_id);
        return return_json_data($data, 200);
    }

    /**
     * 拼团集合
     */
    public function tuangouGather()
    {
        $Pintuan = new TuangouApply();
        $data = $Pintuan->tuangouGather($this->shop_id);

        return return_json_data($data, 200);
    }


}